﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PermissionsCenterMasterForm.aspx.cs"
    Inherits="FX.CC.Andon.WebSite.SystemManage.PermissionsCenterMasterForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>权限中心</title>
    <script src="../lib/boot.js" type="text/javascript"></script>
</head>
<body>
    <div class="mini-splitter" style="width: 100%; height: 100%;">
        <div size="50%" showcollapsebutton="true">
            <div class="mini-fit">
                <div id="grid1" class="mini-datagrid" style="width: 100%; height: 100%;" borderstyle="border:0;"
                    idfield="RoleID" sizelist="[10,20,50,100]" onselectionchanged="onSelectionChanged"
                    selectonload="true" pagesize="10">
                    <div property="columns">
                        <div type="indexcolumn">
                        </div>
                        <div field="RoleName" width="120" headeralign="center" allowsort="true">
                            角色名称</div>
                    </div>
                </div>
            </div>
        </div>
        <div showcollapsebutton="true">
            <div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
                <a class="mini-button" iconcls="icon-save" onclick="save();" plain="true">保存</a>
                <span class="separator"></span><a class="mini-button" onclick="close()" iconcls="icon-close"
                    plain="true">关闭</a>
            </div>
            <div class="mini-fit">
                <div id="treegrid1" class="mini-treegrid" style="width: 100%; height: 100%;" borderstyle="border:0;"
                    showtreeicon="true" treecolumn="taskname" idfield="MenuID" parentfield="ParentMenuID"
                    resultastree="false" allowresize="false" autocheckparent="true" expandonload="true"
                    showcheckbox="true" checkrecursive="true">
                    <div property="columns">
                        <div name="taskname" field="MenuName" width="100%;">
                            菜单名称</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        mini.parse();
        var rolegrid = mini.get("grid1");
        rolegrid.setUrl("../service/SystemManageHandler.ashx?action=GetRoleList");
        rolegrid.load();
        var menugrid = mini.get("treegrid1");
        menugrid.setUrl("../service/SystemManageHandler.ashx?action=GetSysMenuList");
        function onSelectionChanged(e) {
            var grid = e.sender;
            var record = grid.getSelected();
            if (record) {
                $.ajax({
                    url: "../service/SystemManageHandler.ashx?action=GetMenuIdForRoleRight&RoleID=" + record.RoleID,
                    cache: false,
                    success: function (text) {
                        menugrid.setValue(text);
                    }
                });
            }
        }

        function refresh() {
            var record = rolegrid.getSelected();
            if (record) {
                $.ajax({
                    url: "../service/SystemManageHandler.ashx?action=GetMenuIdForRoleRight&RoleID=" + record.RoleID,
                    cache: false,
                    success: function (text) {
                        menugrid.setValue(text);
                    }
                });
            }
        }

        function save() {
            var row = rolegrid.getSelected();
            if (row) {
                var o = {};
                o.RoleID = row.RoleID;
                o.menuIds = menugrid.getValue();
                var json = mini.encode([o]);
                funPostJson(json);
            }
            else {
                mini.alert("请先选择角色记录,然后再勾选菜单.");
            }

        }

        function funPostJson(json) {
            $.ajax({
                url: "../Service/SystemManageHandler.ashx?action=SetRoleRight",
                data: { data: json },
                type: 'POST',
                success: function (text) {
                    if (text) {
                        mini.alert("设置权限成功!");
                        refresh();
                    }
                    else {
                        mini.alert("设置失败,请重试!");
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                }
            });
        }
        function CloseWindow(action) {
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();
        }

        function close() {
            CloseWindow("close");
        }

    </script>
</body>
</html>
